// -*-C++-*-

#include "CommandService_impl.h"

CommandService_impl::CommandService_impl(){
    // Please add extra constructor code here.              
}

CommandService_impl::~CommandService_impl(){
    // Please add extra deconstructor code here.              
}

// コマンドを実行する
char* CommandService_impl::command(const char *command, const char *argv)
{
    CommandItr it;    
    if ((it = m_commands.find(command)) != m_commands.end()) {
        std::string _argv(argv);

        std::string ret = (it->second.first)(_argv);
        return CORBA::string_dup(ret.c_str());
    }
    std::string ret("error: no such command: ");
    ret += command;
    return CORBA::string_dup(ret.c_str());
}

// コマンドのHELPメッセージを返す
char* CommandService_impl::help(const char* command)
{
    CommandItr it;
    if ((it = m_commands.find(command)) != m_commands.end()) {
        return CORBA::string_dup(it->second.second.c_str());
    }
    return CORBA::string_dup("error: no such command");
}

// コマンド一覧を返す
RTMEUS::CommandList* CommandService_impl::list()
{
    RTMEUS::CommandList_var commands = new RTMEUS::CommandList;
    commands->length(m_commands.size());
    CORBA::ULong i(0);
    for(CommandItr it = m_commands.begin(); it != m_commands.end(); it++,i++)
    {
        commands[i] = CORBA::string_dup(it->first.c_str());
    }
    return commands._retn();
}



